package cn.com.fattiger.framework.atomic;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;


public class AtomicDemo {

	
	private static volatile int inc = 0;
	
	private static AtomicInteger atoinc = new AtomicInteger();
	
	private static void increase(){
		inc++;
		atoinc.incrementAndGet();
	}
	
	
	public static void main(String[] args) throws InterruptedException {
		final CountDownLatch latch = new CountDownLatch(10);
		for (int i = 0;i<10;i++){
			new Thread(new Runnable(){
				@Override
				public void run() {
					for (int i = 0;i<10000;i++){
						increase();
					}
					latch.countDown();
				}
			}).start();
		}
		System.out.println(inc);
		while(Thread.activeCount()>1)Thread.yield();
		System.out.println(inc);
		System.out.println(Thread.activeCount());
		System.out.println(atoinc);
		Integer a = new Integer(3);
        Integer b = 3;                  // 将3自动装箱成Integer类型
        int c = 3;
        System.out.println(a == b);     // false 两个引用没有引用同一对象
        System.out.println(a == c);     //
        String s1 = "Programming";
        String s2 = new String("Programming");
        String s3 = "Program" + "ming";
        System.out.println(s1 == s2);
        System.out.println(s1 == s3);
        System.out.println(s1 == s1.intern());
	}

}
